package com.molichuxing.gateway.bff.order.convertor;

import com.alibaba.fastjson.JSONObject;
import com.molichuxing.framework.utils.DateUtil;
import com.molichuxing.framework.utils.ObjectCastUtil;
import com.molichuxing.gateway.bff.order.entity.request.create.*;
import com.molichuxing.gateway.bff.order.entity.request.modify.*;
import com.molichuxing.gateway.bff.order.entity.response.*;
import com.molichuxing.services.business.dto.request.create.*;
import com.molichuxing.services.business.dto.request.modify.*;
import com.molichuxing.services.business.dto.response.*;
import com.molichuxing.services.contants.OrderStatusConst;
import com.molichuxing.services.infrastructure.dto.request.create.ContractEnterpriseCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.ContractFileCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.OfflineBookyueCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.PaymentEnterpriseCreateDto;
import com.molichuxing.services.infrastructure.dto.response.CarDto;
import com.molichuxing.services.infrastructure.dto.response.*;
import com.molichuxing.services.property.*;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class Convert {
    // 里程单位
    public static final String UNIT_MILEAGE = "公里";
    // 金额单位
    public static final String UNIT_MONEY = "元";

    public static OrderSubscribeVo toOrderSubscribeVo(OrderSubscribeBizDto beanDto) {
        OrderSubscribeVo beanVo = null;
        if (beanDto != null) {
            beanVo = new OrderSubscribeVo();
            BeanUtils.copyProperties(beanDto, beanVo);
            Integer totalMileage = beanDto.getBaseMileage() + beanDto.getPackageMileage() + beanDto.getGiftMileage();
            BigDecimal totalAmount = beanDto.getCartFee().add(beanDto.getDeposit());
            // 里程详情
            List<ParamDetailVo> mileageDetail = new ArrayList<>();
            mileageDetail.add(new ParamDetailVo("基础里程", beanDto.getBaseMileage() + UNIT_MILEAGE));
            mileageDetail.add(new ParamDetailVo("订阅里程", beanDto.getPackageMileage() + UNIT_MILEAGE));
            if (beanDto.getGiftMileage() != null && beanDto.getGiftMileage() > 0) {
                mileageDetail.add(new ParamDetailVo("赠送里程", beanDto.getGiftMileage() + UNIT_MILEAGE));
            }
            // 金额详情
            List<ParamDetailVo> amountDetail = new ArrayList<>();
            amountDetail.add(
                    new ParamDetailVo("租车费", beanDto.getRental().stripTrailingZeros().toPlainString() + UNIT_MONEY));
            amountDetail.add(new ParamDetailVo("基础里程费",
                    beanDto.getBaseMileagePrice().stripTrailingZeros().toPlainString() + UNIT_MONEY));
            amountDetail.add(new ParamDetailVo("订阅里程费",
                    beanDto.getPackageMileagePrice().stripTrailingZeros().toPlainString() + UNIT_MONEY));

            if (beanDto.getDeposit() != null && beanDto.getDeposit().compareTo(BigDecimal.ZERO) > 0) {
                amountDetail.add(new ParamDetailVo("保证金",
                        beanDto.getDeposit().stripTrailingZeros().toPlainString() + UNIT_MONEY));
            }

            if (beanDto.getPurchaseMileage() != null && beanDto.getPurchaseMileage() > 0
                    && beanDto.getPurchaseFee() != null) {
                totalMileage = totalMileage + beanDto.getPurchaseMileage();
                totalAmount = totalAmount.add(beanDto.getPurchaseFee());
                mileageDetail.add(new ParamDetailVo("加购里程", beanDto.getPurchaseMileage() + UNIT_MILEAGE));
                amountDetail.add(new ParamDetailVo("加购里程费",
                        beanDto.getPurchaseFee().stripTrailingZeros().toPlainString() + UNIT_MONEY));
            }
            if (beanDto.getBeyondMileage() != null && beanDto.getBeyondMileage() > 0
                    && beanDto.getBeyondFee() != null) {
                totalMileage = totalMileage + beanDto.getBeyondMileage();
                totalAmount = totalAmount.add(beanDto.getBeyondFee());
                mileageDetail.add(new ParamDetailVo("已结算超里程", beanDto.getBeyondMileage() + UNIT_MILEAGE));
                amountDetail.add(new ParamDetailVo("已结算超里程费",
                        beanDto.getBeyondFee().stripTrailingZeros().toPlainString() + UNIT_MONEY));
            }
            // 总里程(基础里程+订阅里程+赠送里程+加购里程+已结算超里程)
            beanVo.setTotalMileage(totalMileage);
            // 订单总金额(租车费+基础里程费+订阅里程费+加购里程费+已结算超里程费)
            beanVo.setTotalAmount(totalAmount);
            // 里程详情
            beanVo.setMileageDetail(mileageDetail);
            // 金额详情
            beanVo.setAmountDetail(amountDetail);

            // 审核状态
            if (OrderSubscribeStatusEnum.TRADE_UNAUDIT.equals(beanDto.getOrderStatus())) {
                // 待审核
                beanVo.setAuditStatusStr(OrderSubscribeStatusEnum.TRADE_UNAUDIT.getName());
            } else if (OrderStatusConst.CREDIT_PASS_SUBSCRIBE_STATUS.contains(beanDto.getOrderStatus())) {
                // 审核通过
                beanVo.setAuditStatusStr(OrderSubscribeStatusEnum.TRADE_PASS.getName());
            } else if (OrderStatusConst.CREDIT_REJECT_SUBSCRIBE_STATUS.contains(beanDto.getOrderStatus())) {
                // 审核驳回
                beanVo.setAuditStatusStr(OrderSubscribeStatusEnum.TRADE_REJECTED.getName());
            }

            // 退款状态
            if (OrderSubscribeStatusEnum.TRADE_REJECTED.equals(beanDto.getOrderStatus())) {
                // 待处理
                beanVo.setRefundStatusStr("待处理");
            } else if (OrderSubscribeStatusEnum.TRADE_REFUND.equals(beanDto.getOrderStatus())) {
                // 退款中
                beanVo.setRefundStatusStr("退款中");
            } else if (OrderSubscribeStatusEnum.TRADE_FINISH.equals(beanDto.getOrderStatus())) {
                // 已退款
                beanVo.setRefundStatusStr("已退款");
            }
        }
        return beanVo;
    }

    public static OrderExclusivelVo toOrderExclusivelVo(OrderExclusivelBizDto beanDto) {
        OrderExclusivelVo beanVo = null;
        if (beanDto != null) {
            beanVo = new OrderExclusivelVo();
            BeanUtils.copyProperties(beanDto, beanVo);
            beanVo.setType(beanDto.getExclusivelType().getValue());
            beanVo.setTypeStr(beanDto.getExclusivelType().getName());
            if (beanDto.getCarId() == null || beanDto.getCarId() <= 0) {
                beanVo.setIsCar(false);
            } else {
                beanVo.setIsCar(true);
            }
            // 付款方式
            beanVo.setPaymentMethodStr(OrderPaymentMethodEnum.INSTALLMENT.equals(beanDto.getPaymentMethod()) ? "月付"
                    : beanDto.getPaymentMethod().getName());
            // 付款方式详情
            List<ParamDetailVo> paymentMethodDetail = new ArrayList<>();
            paymentMethodDetail.add(new ParamDetailVo("还款周期", beanDto.getRepaymentPeriod() + "个月"));
            paymentMethodDetail.add(new ParamDetailVo("首付期数", beanDto.getFirstTerms() + "期"));
            paymentMethodDetail.add(new ParamDetailVo("结算日", beanDto.getSettleDay() + "号"));
            beanVo.setPaymentMethodDetail(paymentMethodDetail);
            // 订单总金额
            beanVo.setTotalAmount(beanDto.getCartFee().add(beanDto.getDeposit()));

            // 审核状态
            if (OrderExclusivelStatusEnum.TRADE_UNAUDIT.equals(beanDto.getOrderStatus())
                    || OrderExclusivelStatusEnum.TRADE_CREDIT_UNAUDIT.equals(beanDto.getOrderStatus())) {
                // 待审核
                beanVo.setAuditStatusStr(OrderExclusivelStatusEnum.TRADE_UNAUDIT.getName());
            } else if (OrderStatusConst.CREDIT_PASS_EXCLUSIVEL_STATUS.contains(beanDto.getOrderStatus())) {
                // 审核通过
                beanVo.setAuditStatusStr(OrderExclusivelStatusEnum.TRADE_PASS.getName());
            } else if (OrderStatusConst.CREDIT_REJECT_EXCLUSIVEL_STATUS.contains(beanDto.getOrderStatus())) {
                // 审核驳回
                beanVo.setAuditStatusStr(OrderExclusivelStatusEnum.TRADE_REJECTED.getName());
            }

            // 退款状态
            if (OrderExclusivelStatusEnum.TRADE_REJECTED.equals(beanDto.getOrderStatus())) {
                // 待处理
                beanVo.setRefundStatusStr("待处理");
            } else if (OrderExclusivelStatusEnum.TRADE_REFUND.equals(beanDto.getOrderStatus())) {
                // 退款中
                beanVo.setRefundStatusStr("退款中");
            } else if (OrderExclusivelStatusEnum.TRADE_FINISH.equals(beanDto.getOrderStatus())) {
                // 已退款
                beanVo.setRefundStatusStr("已退款");
            }

        }
        return beanVo;
    }

    public static OrderRepaymentVo toOrderRepaymentVo(OrderScheduleCurrentPeriodDto beanDto) {
        OrderRepaymentVo beanVo = null;
        if (beanDto != null) {
            beanVo = new OrderRepaymentVo();
            BeanUtils.copyProperties(beanDto, beanVo);
        }
        return beanVo;
    }

    public static OrderOverdueVo toOrderOverdueVo(OrderScheduleOverdueDto beanDto) {
        OrderOverdueVo beanVo = null;
        if (beanDto != null) {
            beanVo = new OrderOverdueVo();
            BeanUtils.copyProperties(beanDto, beanVo);
            if (beanDto.getOrderStatus() != null) {
                beanVo.setOrderStatus(beanDto.getOrderStatus().getValue());
                beanVo.setOrderStatusStr(beanDto.getOrderStatus().getName());
                beanVo.setIsRenege(OrderExclusivelStatusEnum.RENEGE_ACCEPTED.getValue()
                        <= beanDto.getOrderStatus().getValue());
            }
        }
        return beanVo;
    }

    public static OrderRepaymentDetailVo toOrderRepaymentDetailVo(OrderScheduleDto beanDto) {
        return toOrderRepaymentDetailVo(beanDto, null);
    }

    public static OrderRepaymentDetailVo toOrderRepaymentDetailVo(OrderScheduleDto beanDto, OrderReturnDto orderReturn) {
        OrderRepaymentDetailVo beanVo = null;
        if (beanDto != null) {
            beanVo = new OrderRepaymentDetailVo();
            BeanUtils.copyProperties(beanDto, beanVo);
            beanVo.setPeriodsStr(beanDto.getPeriods() + "/" + beanDto.getTotalPeriods());
            beanVo.setStatus(beanDto.getStatus().getValue());
            beanVo.setStatusStr(beanDto.getStatus().getName());
            if (OrderScheduleStatusEnum.ALREADY.equals(beanDto.getStatus())) {
                // 已还款，判断逾期时间为支付时间
                long overdueDay = DateUtil.getDaysDiff(beanDto.getPayableDate(), beanDto.getPaySuccessTime());
                if (overdueDay > 0L) {
                    // 逾期
                    beanVo.setIsOverdue(true);
                    beanVo.setIsOverdueStr("是");
                    beanVo.setOverdueDays((int) overdueDay);
                    beanVo.setOverdueDaysStr(beanVo.getOverdueDays() + "天");
                } else {
                    // 未逾期
                    beanVo.setIsOverdue(false);
                    beanVo.setIsOverdueStr("否");
                    beanVo.setOverdueDays(0);
                    beanVo.setOverdueDaysStr("--");
                }
            } else {
                // 未还款，判断逾期时间
                long overdueDay = 0L;
                if (orderReturn == null || orderReturn.getReturnTime() == null) {
                    // 无还车信息或还车时间为空，使用当前时间
                    overdueDay = DateUtil.getDaysDiff(beanDto.getPayableDate(), LocalDate.now());
                } else {
                    // 有还车信息，使用还车时间
                    overdueDay = DateUtil.getDaysDiff(beanDto.getPayableDate(), orderReturn.getReturnTime());
                }
                if (overdueDay > 0) {
                    // 逾期
                    beanVo.setIsOverdue(true);
                    beanVo.setIsOverdueStr("是");
                    beanVo.setOverdueDays((int) overdueDay);
                    beanVo.setOverdueDaysStr(beanVo.getOverdueDays() + "天");
                } else {
                    // 未逾期
                    beanVo.setIsOverdue(false);
                    beanVo.setIsOverdueStr("--");
                    beanVo.setOverdueDays(0);
                    beanVo.setOverdueDaysStr("--");
                }
            }
        }
        return beanVo;
    }

    public static List<OrderTradeFlowVo> toOrderTradeFlowVo(List<OrderTradeFlowBizDto> beanDtoList) {
        List<OrderTradeFlowVo> beanVoList = null;
        if (beanDtoList != null && !beanDtoList.isEmpty()) {
            beanVoList = new ArrayList<>();
            for (OrderTradeFlowBizDto beanDto : beanDtoList) {
                beanVoList.add(toOrderTradeFlowVo(beanDto));
            }
        }
        return beanVoList;
    }

    public static OrderTradeFlowVo toOrderTradeFlowVo(OrderTradeFlowBizDto beanDto) {
        OrderTradeFlowVo beanVo = null;
        if (beanDto != null) {
            beanVo = new OrderTradeFlowVo();
            BeanUtils.copyProperties(beanDto, beanVo);
        }

        return beanVo;
    }

    public static OrderSubscribeBaseVo toOrderSubscribeBaseVo(OrderSubscribeBizDto beanDto) {
        OrderSubscribeBaseVo beanVo = null;
        if (beanDto != null) {
            beanVo = new OrderSubscribeBaseVo();
            BeanUtils.copyProperties(beanDto, beanVo);

            Integer totalMileage = beanDto.getBaseMileage() + beanDto.getPackageMileage() + beanDto.getGiftMileage();
            BigDecimal totalAmount = beanDto.getCartFee().add(beanDto.getDeposit());

            if (beanDto.getPurchaseMileage() != null && beanDto.getPurchaseMileage() > 0) {
                totalMileage = totalMileage + beanDto.getPurchaseMileage();
                totalAmount = totalAmount.add(beanDto.getPurchaseFee());
            }
            if (beanDto.getBeyondMileage() != null && beanDto.getBeyondMileage() > 0) {
                totalMileage = totalMileage + beanDto.getBeyondMileage();
                totalAmount = totalAmount.add(beanDto.getBeyondFee());
            }
            // 总里程(基础里程+订阅里程+赠送里程+加购里程+已结算超里程)
            beanVo.setTotalMileage(totalMileage);
            // 订单总金额(租车费+基础里程费+订阅里程费+加购里程费+已结算超里程费+保证金)
            beanVo.setTotalAmount(totalAmount);

            // 是否续订订单
            if (beanDto.getParentOrderCode() == null || beanDto.getParentOrderCode() == 0L) {
                beanVo.setIsRenew(false);
            } else {
                beanVo.setIsRenew(true);
            }
        }

        return beanVo;
    }

    public static OrderExclusivelBaseVo toOrderExclusivelBaseVo(OrderExclusivelDto beanDto) {
        OrderExclusivelBaseVo beanVo = null;
        if (beanDto != null) {
            beanVo = new OrderExclusivelBaseVo();
            BeanUtils.copyProperties(beanDto, beanVo);
            beanVo.setType(beanDto.getType().getValue());
            beanVo.setTypeStr(beanDto.getType().getName());
            beanVo.setTotalAmount(beanDto.getCartFee().add(beanDto.getDeposit()));
            // 还款总期数(用车时长/还款周期)
            if (beanDto.getTransferTime() != null && beanDto.getRepaymentPeriod() != null
                    && beanDto.getRepaymentPeriod() > 0) {
                beanVo.setTotalPeriods((int) Math.ceil(beanDto.getTransportTime() / beanDto.getRepaymentPeriod()));
            }
        }

        return beanVo;
    }

    public static OrderUsedCarVo toOrderUsedCarVo(OrderUsedCarBizDto beanDto) {
        OrderUsedCarVo beanVo = null;
        if (beanDto != null) {
            beanVo = new OrderUsedCarVo();
            BeanUtils.copyProperties(beanDto, beanVo);
            beanVo.setPurchaseMileage(beanDto.getReletMileage());
            beanVo.setBeyondMileage(beanDto.getBeyondMileage() == null ? 0 : beanDto.getBeyondMileage());
        }

        return beanVo;
    }

    public static UserOrderVo toUserOrderVo(UserOrderBizDto beanDto) {
        UserOrderVo beanVo = null;
        if (beanDto != null) {
            beanVo = new UserOrderVo();
            BeanUtils.copyProperties(beanDto, beanVo);
            if (OrderTypeEnum.EXCLUSIVEL.equals(beanDto.getOrderType())) {
                // 专属里程订单
                OrderExclusivelStatusEnum orderStatus = (OrderExclusivelStatusEnum) beanDto.getOrderStatus();
                beanVo.setOrderStatus(orderStatus.getValue());
                beanVo.setOrderStatusStr(orderStatus.getName());
            } else if (OrderTypeEnum.SUBSCRIBE.equals(beanDto.getOrderType())) {
                // 订阅里程订单
                OrderSubscribeStatusEnum orderStatus = (OrderSubscribeStatusEnum) beanDto.getOrderStatus();
                beanVo.setOrderStatus(orderStatus.getValue());
                beanVo.setOrderStatusStr(orderStatus.getName());
            }
        }

        return beanVo;
    }

    public static CarOrderVo toCarOrderVo(CarOrderBizDto beanDto) {
        CarOrderVo beanVo = null;
        if (beanDto != null) {
            beanVo = new CarOrderVo();
            BeanUtils.copyProperties(beanDto, beanVo);
            beanVo.setPaymentMethod(beanDto.getPaymentMethod().getValue());
            beanVo.setPaymentMethodStr(beanDto.getPaymentMethod().getName());
            if (OrderTypeEnum.EXCLUSIVEL.equals(beanDto.getOrderType())) {
                // 专属里程订单
                OrderExclusivelStatusEnum orderStatus = (OrderExclusivelStatusEnum) beanDto.getOrderStatus();
                beanVo.setOrderStatus(orderStatus.getValue());
                beanVo.setOrderStatusStr(orderStatus.getName());
            } else if (OrderTypeEnum.SUBSCRIBE.equals(beanDto.getOrderType())) {
                // 订阅里程订单
                OrderSubscribeStatusEnum orderStatus = (OrderSubscribeStatusEnum) beanDto.getOrderStatus();
                beanVo.setOrderStatus(orderStatus.getValue());
                beanVo.setOrderStatusStr(orderStatus.getName());
            }
        }

        return beanVo;
    }

    public static PaymentOfflineScheduleVo toOrderScheduleOfflineVo(OrderScheduleOfflineBizDto beanDto) {
        PaymentOfflineScheduleVo beanVo = null;
        if (beanDto != null) {
            beanVo = new PaymentOfflineScheduleVo();
            BeanUtils.copyProperties(beanDto, beanVo);
        }

        return beanVo;
    }

    public static OfflineBizCreateDto toOfflineBizCreateDto(PaymentOfflineCreateVo createVo) {
        OfflineBizCreateDto createDto = new OfflineBizCreateDto();
        BeanUtils.copyProperties(createVo, createDto);
        createDto.setPayTime(ObjectCastUtil.castLocalDateTime(createVo.getPayTime()));
        createDto.setVoucherImgList(createVo.getVoucherImgs());
        // 申请人信息
        createDto.setApplyId(createVo.getOperateId());
        createDto.setApplyName(createVo.getOperateName());
        createDto.setApplyTime(createVo.getOperateDate());

        List<OfflineOrdersBizCreateDto> offlineOrdersList = new ArrayList<>();
        OfflineOrdersBizCreateDto offlineOrdersBizCreateDto = null;
        for (PaymentOfflineScheduleCreateVo offlineOrdersBizCreateVo : createVo.getOfflineOrdersList()) {
            offlineOrdersBizCreateDto = new OfflineOrdersBizCreateDto();
            BeanUtils.copyProperties(offlineOrdersBizCreateVo, offlineOrdersBizCreateDto);
            offlineOrdersList.add(offlineOrdersBizCreateDto);
        }
        createDto.setOfflineOrdersList(offlineOrdersList);

        return createDto;
    }

    public static List<OrderContractVo> toOrderContractVo(List<ContractDto> beanDtoList) {
        List<OrderContractVo> beanVoList = null;
        if (beanDtoList != null && !beanDtoList.isEmpty()) {
            beanVoList = new ArrayList<>();
            for (ContractDto beanDto : beanDtoList) {
                beanVoList.add(toOrderContractVo(beanDto));
            }
        }
        return beanVoList;
    }

    public static OrderContractVo toOrderContractVo(ContractDto beanDto) {
        OrderContractVo beanVo = null;
        if (beanDto != null) {
            beanVo = new OrderContractVo();
            BeanUtils.copyProperties(beanDto, beanVo);
            beanVo.setContractName(beanVo.getContractName() == null ? null
                    : beanVo.getContractName().replace("《", "").replace("》", ""));
        }

        return beanVo;
    }

    public static OrderTradeAuditModifyBizDto toOrderAuditModifyBizDto(OrderTradeAuditModifyVo modifyVo,
                                                                       OrderAuditResultEnum auditResult) {
        OrderTradeAuditModifyBizDto modifyBizDto = null;
        if (modifyVo != null) {
            modifyBizDto = new OrderTradeAuditModifyBizDto();
            BeanUtils.copyProperties(modifyVo, modifyBizDto);
            modifyBizDto.setResult(auditResult);
            modifyBizDto.setAuditId(modifyVo.getOperateId());
            modifyBizDto.setAuditName(modifyVo.getOperateName());
        }

        return modifyBizDto;
    }

    public static OrderAuditVo toOrderAuditVo(OrderAuditDto beanDto) {
        OrderAuditVo beanVo = null;
        if (beanDto != null) {
            beanVo = new OrderAuditVo();
            BeanUtils.copyProperties(beanDto, beanVo);
            beanVo.setResult(beanDto.getResult().getValue());
            beanVo.setResultStr(beanDto.getResult().getName());
        }
        return beanVo;
    }

    public static OrderTradeRefundModifyBizDto toOrderTradeRefundModifyBizDto(OrderTradeRefundModifyVo modifyVo) {
        OrderTradeRefundModifyBizDto modifyBizDto = null;
        if (modifyVo == null) {
            return modifyBizDto;
        }
        modifyBizDto = new OrderTradeRefundModifyBizDto();
        BeanUtils.copyProperties(modifyVo, modifyBizDto);
        modifyBizDto.setType(OrderTradeRefundTypeEnum.getEnum(modifyVo.getType()));
        modifyBizDto.setModifiedType(OrderStatusFlowModifiedTypeEnum.B_USER);

        return modifyBizDto;
    }

    public static OrderTradeAuditModifyBizDto toOrderTradeAuditModifyBizDto(OrderCreditAuditModifyVo modifyVo,
                                                                            OrderAuditResultEnum auditResult) {
        OrderTradeAuditModifyBizDto modifyBizDto = null;
        if (modifyVo != null) {
            modifyBizDto = new OrderTradeAuditModifyBizDto();
            BeanUtils.copyProperties(modifyVo, modifyBizDto);
            modifyBizDto.setResult(auditResult);
            modifyBizDto.setAuditId(modifyVo.getOperateId());
            modifyBizDto.setAuditName(modifyVo.getOperateName());
        }

        return modifyBizDto;
    }


    public static OrderPayModifyBizDto toOrderPayModifyBizDto(OrderOfflineDownPayModifyVo modifyVo) {
        OrderPayModifyBizDto modifyBizDto = null;
        if (modifyVo == null) {
            return modifyBizDto;
        }
        modifyBizDto = new OrderPayModifyBizDto();
        BeanUtils.copyProperties(modifyVo, modifyBizDto);
        modifyBizDto.setOrderCode(modifyVo.getOrderCode());
        modifyBizDto.setPayWay(OrderPayWayEnum.OFFLINE);
        modifyBizDto.setPayTime(LocalDateTime.now());

        return modifyBizDto;
    }

    public static OfflineBookyueCreateDto toOfflineBookyueCreateDto(OrderOfflineDownPayModifyVo modifyVo) {
        OfflineBookyueCreateDto createDto = null;
        if (modifyVo == null) {
            return createDto;
        }
        createDto = new OfflineBookyueCreateDto();
        BeanUtils.copyProperties(modifyVo, createDto);
        createDto.setOrderCode(modifyVo.getOrderCode());
        createDto.setVoucher(JSONObject.toJSONString(modifyVo.getVoucherUrls()));
        createDto.setOptId(modifyVo.getOperateId());
        createDto.setOptName(modifyVo.getOperateName());
        createDto.setOptTime(LocalDateTime.now());
        return createDto;
    }

    public static OrderTradeDeliveryModifyBizDto toOrderTradeDeliveryModifyBizDto(OrderOfflineDeliveryModifyVo modifyVo,
                                                                                  OrderExclusivelDto orderExclusivelDto) {
        OrderTradeDeliveryModifyBizDto modifyBizDto = new OrderTradeDeliveryModifyBizDto();
        BeanUtils.copyProperties(modifyVo, modifyBizDto);
        modifyBizDto.setOrderCode(modifyVo.getOrderCode());
        modifyBizDto.setCarId(0);
        modifyBizDto.setWarningMileage(0);
        modifyBizDto.setStartMileage(0);
        modifyBizDto.setStoreId(orderExclusivelDto.getPlaceStoreId());
        modifyBizDto.setSalesmanId(0);

        return modifyBizDto;
    }

    public static OrderRenegeCreateBizDto toOrderRenegeCreateBizDto(OrderRenegeCreateVo vo) {
        OrderRenegeCreateBizDto dto = null;
        if (vo != null) {
            dto = new OrderRenegeCreateBizDto();
            BeanUtils.copyProperties(vo, dto);
            dto.setRenegeType(OrderRenegeTypeEnum.getEnum(vo.getRenegeType()));
        }
        return dto;
    }

    public static OrderRenegeCancelModifyBizDto toOrderRenegeCancelModifyBizDto(OrderRenegeCancelModifyVo vo) {
        OrderRenegeCancelModifyBizDto dto = null;
        if (vo != null) {
            dto = new OrderRenegeCancelModifyBizDto();
            BeanUtils.copyProperties(vo, dto);
        }
        return dto;
    }

    public static OrderRenegeCostModifyBizDto toOrderRenegeCostModifyBizDto(OrderRenegeCostModifyVo vo) {
        OrderRenegeCostModifyBizDto dto = null;
        if (vo != null) {
            dto = new OrderRenegeCostModifyBizDto();
            BeanUtils.copyProperties(vo, dto);
            OrderRenegeCostTypeEnum orderRenegeCostTypeEnum = OrderRenegeCostTypeEnum.getEnum(vo.getCostType());
            dto.setCostType(orderRenegeCostTypeEnum);
        }
        return dto;
    }

    public static OrderRenegeCompleteModifyBizDto toOrderRenegeCompleteModifyBizDto(OrderRenegeCompleteModifyVo vo) {
        OrderRenegeCompleteModifyBizDto dto = null;
        if (vo != null) {
            dto = new OrderRenegeCompleteModifyBizDto();
            BeanUtils.copyProperties(vo, dto);
        }
        return dto;
    }

    public static OrderRenegeVo toOrderRenegeVo(OrderRenegeBizDto dto) {
        OrderRenegeVo vo = null;
        if (dto != null) {
            vo = new OrderRenegeVo();
            BeanUtils.copyProperties(dto, vo);
            vo.setCostType(dto.getCostType() == null ? null : dto.getCostType().getValue());
            vo.setCostTypeStr(dto.getCostType() == null ? null : dto.getCostType().getName());
        }
        return vo;
    }

    public static List<EnterpriseScheduleVo> toEnterpriseScheduleVoList(List<EnterpriseScheduleBizDto> bizDtoList,
                                                                        Map<Integer, EnterpriseDto> enterpriseMap) {
        List<EnterpriseScheduleVo> voList = new ArrayList<>();
        if (bizDtoList != null && bizDtoList.size() > 0) {
            for (EnterpriseScheduleBizDto bizDto : bizDtoList) {
                voList.add(toEnterpriseScheduleVo(bizDto, enterpriseMap));
            }
        }
        return voList;
    }

    public static EnterpriseScheduleVo toEnterpriseScheduleVo(EnterpriseScheduleBizDto bizDto,
                                                              Map<Integer, EnterpriseDto> enterpriseMap) {
        if (null == bizDto) {
            return null;
        }
        EnterpriseScheduleVo vo = new EnterpriseScheduleVo();
        BeanUtils.copyProperties(bizDto, vo);
        Integer enterpriseId = bizDto.getEnterpriseId();
        if (enterpriseMap != null && enterpriseMap.size() > 0) {
            EnterpriseDto enterpriseDto = enterpriseMap.get(enterpriseId);
            if (enterpriseDto != null) {
                String name = enterpriseDto.getName();
                vo.setEnterpriseName(name);
            }
        }

        return vo;
    }

    public static List<EnterpriseScheduleVo> toEnterpriseScheduleList(List<PaymentEnterpriseDto> bizDtoList,
                                                                      Map<Integer, EnterpriseScheduleBizDto> scheduleMap,
                                                                      Map<Integer, EnterpriseDto> enterpriseMap,
                                                                      Map<Long, OrderEnterpriseDto> orderEnterpriseMap) {
        List<EnterpriseScheduleVo> voList = new ArrayList<>();
        if (bizDtoList != null && bizDtoList.size() > 0) {
            for (PaymentEnterpriseDto bizDto : bizDtoList) {
                voList.add(toEnterpriseSchedule(bizDto, scheduleMap, enterpriseMap, orderEnterpriseMap));
            }
        }
        return voList;
    }

    public static EnterpriseScheduleVo toEnterpriseSchedule(PaymentEnterpriseDto bizDto,
                                                            Map<Integer, EnterpriseScheduleBizDto> scheduleMap,
                                                            Map<Integer, EnterpriseDto> enterpriseMap,
                                                            Map<Long, OrderEnterpriseDto> orderEnterpriseMap) {
        if (null == bizDto) {
            return null;
        }
        EnterpriseScheduleVo vo = new EnterpriseScheduleVo();
        BeanUtils.copyProperties(bizDto, vo);
        Integer scheduleId = bizDto.getScheduleId();
        Integer enterpriseId = bizDto.getEnterpriseId();
        Long orderCode = bizDto.getOrderCode();
        if (scheduleMap != null && scheduleMap.size() > 0) {
            EnterpriseScheduleBizDto enterpriseScheduleBizDto = scheduleMap.get(scheduleId);
            if (enterpriseScheduleBizDto != null) {
                Integer periods = enterpriseScheduleBizDto.getPeriods();
                Integer totalPeriods = enterpriseScheduleBizDto.getTotalPeriods();
                BigDecimal allPayable = enterpriseScheduleBizDto.getAllPayable();
                vo.setPeriods(periods);
                vo.setTotalPeriods(totalPeriods);
                vo.setAllPayable(getAllPayable(periods, orderEnterpriseMap, orderCode, allPayable));
            }
        }

        if (enterpriseMap != null && enterpriseMap.size() > 0) {
            EnterpriseDto enterpriseDto = enterpriseMap.get(enterpriseId);
            if (enterpriseDto != null) {
                String name = enterpriseDto.getName();
                vo.setEnterpriseName(name);
            }
        }
        return vo;
    }

    private static BigDecimal getAllPayable(Integer periods, Map<Long, OrderEnterpriseDto> orderEnterpriseMap, Long orderCode, BigDecimal allPayable) {
        if (null == periods || periods != 1 || null == orderEnterpriseMap || orderEnterpriseMap.size() < 1) {
            return allPayable;
        }

        OrderEnterpriseDto orderEnterpriseDto = orderEnterpriseMap.get(orderCode);
        if (null == orderEnterpriseDto) {
            return allPayable;
        }
        BigDecimal deposit = orderEnterpriseDto.getDeposit();
        if (null == deposit) {
            deposit = BigDecimal.ZERO;
        }
        if (null == allPayable) {
            allPayable = BigDecimal.ZERO;
        }
        return allPayable = allPayable.add(deposit);
    }

    public static PaymentEnterpriseInfoVo toPaymentEnterpriseInfoVo(EnterpriseScheduleDto enterpriseScheduleDto,
                                                                    PaymentEnterpriseDto paymentEnterpriseDto) {

        PaymentEnterpriseInfoVo vo = new PaymentEnterpriseInfoVo();
        if (enterpriseScheduleDto != null) {
            BeanUtils.copyProperties(enterpriseScheduleDto, vo);
        }
        if (paymentEnterpriseDto != null) {
            BeanUtils.copyProperties(paymentEnterpriseDto, vo);
        }
        return vo;
    }

    public static OrderEnterpriseCarDetailVo toOrderEnterpriseCarDetailVo(Long orderCode, Map<Integer, List<EnterpriseCarDto>> dtoMap,
                                                                          Map<Integer, CarDto> carMap,
                                                                          Map<Integer, VehicleNameBizDto> vehicleMap,
                                                                          Map<Integer, VehicleColorDto> colorMap) {
        if (dtoMap == null || dtoMap.isEmpty()) {
            return null;
        }
        OrderEnterpriseCarDetailVo vo = new OrderEnterpriseCarDetailVo(orderCode, BigDecimal.ZERO, BigDecimal.ZERO,
                new ArrayList<>(vehicleMap.size()));

        // 遍历车型
        vehicleMap.forEach((modelId, vehicleNameBizDto) -> {
            // 获取该车型下的车辆信息
            List<EnterpriseCarDto> enterpriseCarDtos = dtoMap.get(modelId);
            // 车型明细
            EnterpriseModelDetailVo modelDetailVo = new EnterpriseModelDetailVo(vehicleNameBizDto.getModelName(),
                    enterpriseCarDtos.size(), new ArrayList<>(enterpriseCarDtos.size()));
            // 遍历
            enterpriseCarDtos.forEach(enterpriseCarDto -> {
                // 总保证金
                vo.setDeposit(vo.getDeposit().add(enterpriseCarDto.getDeposit()));
                // 总金额/期
                vo.setPeriodsRental(vo.getPeriodsRental().add(enterpriseCarDto.getPeriodsRental()));

                // 车辆明细
                EnterpriseCarDetailVo carDetailVo = new EnterpriseCarDetailVo(null, null, null,
                        enterpriseCarDto.getStartMileage(), enterpriseCarDto.getMileageUpper(), enterpriseCarDto.getDeposit(), enterpriseCarDto.getPeriodsRental());

                carDetailVo.setStatus(enterpriseCarDto.getState());
                carDetailVo.setStatusStr(EnterpriseCarStateEnum.getName(enterpriseCarDto.getState()));

                // 获取车辆信息
                if (carMap != null) {
                    CarDto carDto = carMap.get(enterpriseCarDto.getCarId());
                    carDetailVo.setVin(carDto == null ? null : carDto.getVin());
                    carDetailVo.setLicencePlate(carDto == null ? null : carDto.getLicencePlate());
                }
                // 获取车身颜色信息
                if (colorMap != null) {
                    VehicleColorDto vehicleColorDto = colorMap.get(enterpriseCarDto.getColorId());
                    carDetailVo.setColorName(vehicleColorDto == null ? null : vehicleColorDto.getName());
                }
                modelDetailVo.getCarDetail().add(carDetailVo);
            });
            vo.getModelDetail().add(modelDetailVo);
        });

        return vo;

    }

    public static List<OrderEnterpriseCarHandoverVo> toOrderEnterpriseCarHandoverVo(List<EnterpriseCarHandoverDto> dtoList,
                                                                                    Map<Integer, CarDto> carMap,
                                                                                    Map<Integer, VehicleNameBizDto> vehicleMap,
                                                                                    Map<Integer, VehicleColorDto> colorMap,
                                                                                    Map<Integer, ContractEnterpriseDto> deliveryMap) {
        if (dtoList == null || dtoList.isEmpty()) {
            return null;
        }
        List<OrderEnterpriseCarHandoverVo> voList = new ArrayList<>();
        dtoList.forEach(dto -> {
            OrderEnterpriseCarHandoverVo vo = Convert.toOrderEnterpriseCarHandoverVo(dto);
            // 车辆信息
            if (carMap != null) {
                CarDto carDto = carMap.get(dto.getCarId());
                vo.setVin(carDto == null ? null : carDto.getVin());
                vo.setLicencePlate(carDto == null ? null : carDto.getLicencePlate());
            }
            // 车型信息
            if (vehicleMap != null) {
                VehicleNameBizDto vehicleNameBizDto = vehicleMap.get(dto.getModelId());
                vo.setModelName(vehicleNameBizDto == null ? null : vehicleNameBizDto.getModelName());
            }
            // 颜色信息
            if (colorMap != null) {
                VehicleColorDto vehicleColorDto = colorMap.get(dto.getColorId());
                vo.setColorName(vehicleColorDto == null ? null : vehicleColorDto.getName());
            }
            // 交车单信息
            if (deliveryMap != null) {
                ContractEnterpriseDto contractEnterpriseDto = deliveryMap.get(dto.getCarId());
                List<ContractFileDto> contracts = contractEnterpriseDto.getContractUrls();
                vo.setHandoverUrl(contracts == null ? null : contracts.isEmpty() ? null : contracts.get(0).getContractName());
                vo.setHandoverUrl(contracts == null ? null : contracts.isEmpty() ? null : contracts.get(0).getContractUrl());
            }
            voList.add(vo);
        });

        return voList;
    }

    private static OrderEnterpriseCarHandoverVo toOrderEnterpriseCarHandoverVo(EnterpriseCarHandoverDto dto) {
        if (dto == null) {
            return null;
        }
        OrderEnterpriseCarHandoverVo vo = new OrderEnterpriseCarHandoverVo();
        BeanUtils.copyProperties(dto, vo);
        return vo;
    }

    public static OrderEnterpriseCreateBizDto toOrderEnterpriseCreateBizDto(OrderEnterpriseCreateVo createVo) {
        if (createVo == null) {
            return null;
        }
        OrderEnterpriseCreateBizDto createBizDto = new OrderEnterpriseCreateBizDto();
        BeanUtils.copyProperties(createVo, createBizDto);
        List<OrderEnterpriseCreateBizDto.EnterpriseCarCreateBizDto> cars = new ArrayList<>();
        createVo.getCars().forEach(carCreateVo -> {
            OrderEnterpriseCreateBizDto.EnterpriseCarCreateBizDto carCreateBizDto = createBizDto.new EnterpriseCarCreateBizDto();
            BeanUtils.copyProperties(carCreateVo, carCreateBizDto);
            cars.add(carCreateBizDto);
        });
        createBizDto.setCars(cars);

        return createBizDto;
    }

    public static OrderEnterpriseCreateBizDto toOrderEnterpriseCreateBizDto(OrderEnterpriseCreateVo createVo,
                                                                            Map<Integer, CarDto> carMap) {
        if (createVo == null) {
            return null;
        }
        OrderEnterpriseCreateBizDto createBizDto = new OrderEnterpriseCreateBizDto();
        BeanUtils.copyProperties(createVo, createBizDto);
        List<OrderEnterpriseCreateBizDto.EnterpriseCarCreateBizDto> cars = new ArrayList<>();
        createVo.getCars().forEach(carCreateVo -> {
            OrderEnterpriseCreateBizDto.EnterpriseCarCreateBizDto carCreateBizDto = createBizDto.new EnterpriseCarCreateBizDto();
            BeanUtils.copyProperties(carCreateVo, carCreateBizDto);
            CarDto carDto = carMap.get(carCreateVo.getCarId());
            carCreateBizDto.setVin(carDto.getVin());
            carCreateBizDto.setLicencePlate(carDto.getLicencePlate());
            cars.add(carCreateBizDto);
        });
        createBizDto.setCars(cars);

        return createBizDto;
    }

    public static OrderEnterpriseCreateBizDto toRenewOrderEnterpriseCreateBizDto(OrderEnterpriseCreateVo createVo,
                                                                                 Map<Integer, EnterpriseCarDto> enterpriseCarMap) {
        if (createVo == null) {
            return null;
        }
        OrderEnterpriseCreateBizDto createBizDto = new OrderEnterpriseCreateBizDto();
        BeanUtils.copyProperties(createVo, createBizDto);
        List<OrderEnterpriseCreateBizDto.EnterpriseCarCreateBizDto> cars = new ArrayList<>();
        createVo.getCars().forEach(carCreateVo -> {
            OrderEnterpriseCreateBizDto.EnterpriseCarCreateBizDto carCreateBizDto = createBizDto.new EnterpriseCarCreateBizDto();
            BeanUtils.copyProperties(carCreateVo, carCreateBizDto);
            EnterpriseCarDto enterpriseCarDto = enterpriseCarMap.get(carCreateVo.getCarId());
            carCreateBizDto.setVin(enterpriseCarDto.getVin());
            carCreateBizDto.setLicencePlate(enterpriseCarDto.getLicencePlate());
            cars.add(carCreateBizDto);
        });
        createBizDto.setCars(cars);

        return createBizDto;
    }

    public static ContractEnterpriseCreateDto toContractEnterpriseCreateDto(OrderEnterpriseCreateVo createVo) {
        if (createVo == null) {
            return null;
        }
        ContractEnterpriseCreateDto createDto = new ContractEnterpriseCreateDto();
        BeanUtils.copyProperties(createVo, createDto);
        createDto.setContractType(ContractEnterpriseTypeEnum.ORDER_CONTRACT.getValue());
        createDto.setContractDate(DateUtil.parseDate(createVo.getContractDate()));
        createDto.setContractUrls(toContractFileCreateDto(createVo.getContractUrls()));

        return createDto;
    }

    public static List<ContractFileCreateDto> toContractFileCreateDto(List<ContractPathVo> volist) {
        if (volist == null || volist.isEmpty()) {
            return null;
        }
        List<ContractFileCreateDto> createDtoList = new ArrayList<>();
        for (ContractPathVo vo : volist) {
            ContractFileCreateDto createDto = new ContractFileCreateDto();
            BeanUtils.copyProperties(vo, createDto);
            createDtoList.add(createDto);
        }

        return createDtoList;
    }

    public static EnterpriseCarTransferVo toEnterpriseCarTransferVo(EnterpriseCarTransferDto dto) {
        if (dto == null) {
            return null;
        }
        EnterpriseCarTransferVo vo = new EnterpriseCarTransferVo();
        BeanUtils.copyProperties(dto, vo);
        return vo;
    }

    public static OrderEnterpriseReturnCreateBizDto toOrderEnterpriseReturnCreateBizDto(OrderEnterpriseReturnCreateVo createVo) {
        if (createVo == null) {
            return null;
        }
        OrderEnterpriseReturnCreateBizDto createDto = new OrderEnterpriseReturnCreateBizDto();
        BeanUtils.copyProperties(createVo, createDto);
        return createDto;
    }

    public static OrderEnterpriseDeliveryCreateBizDto toOrderEnterpriseDeliveryCreateBizDto(OrderEnterpriseDeliveryCreateVo createVo) {
        if (createVo == null) {
            return null;
        }
        OrderEnterpriseDeliveryCreateBizDto createDto = new OrderEnterpriseDeliveryCreateBizDto();
        BeanUtils.copyProperties(createVo, createDto);
        return createDto;
    }

    public static ContractEnterpriseCreateDto toContractEnterpriseCreateDto(OrderEnterpriseReturnCreateVo createVo) {
        if (createVo == null) {
            return null;
        }
        ContractEnterpriseCreateDto createDto = new ContractEnterpriseCreateDto();
        BeanUtils.copyProperties(createVo, createDto);
        createDto.setContractType(ContractEnterpriseTypeEnum.RETURN_CAR_CONTRACT.getValue());

        createDto.setContractUrls(Arrays.asList(
                new ContractFileCreateDto(createVo.getContractName(), createVo.getContractUrl())));
        return createDto;
    }

    public static CarModifyDto toCarModifyDto(OrderEnterpriseReturnCreateVo createVo) {
        if (createVo == null) {
            return null;
        }
        CarModifyDto dto = new CarModifyDto();
        dto.setId(createVo.getCarId());
        dto.setStatus(CarsOperateStatusEnum.FOR_RENT.getValue());
        dto.setStockId(createVo.getHandoverStockId());
        dto.setStockType(StockTypeEnum.ENTREPOT_STORAGE.getValue());
        dto.setVehicleType(CarsTypeEnum.USED_CAR.getValue());
        return dto;
    }

    public static CarModifyDto toCarModifyDto(OrderEnterpriseDeliveryCreateVo createVo) {
        if (createVo == null) {
            return null;
        }
        CarModifyDto dto = new CarModifyDto();
        dto.setId(createVo.getCarId());
        dto.setStatus(CarsOperateStatusEnum.RENTED.getValue());
        dto.setBusinessType(CarsBusinessTypeEnum.KEY_ACCOUNT.getValue());
        return dto;
    }

    public static ContractEnterpriseCreateDto toContractEnterpriseCreateDto(OrderEnterpriseDeliveryCreateVo createVo) {
        if (createVo == null) {
            return null;
        }
        ContractEnterpriseCreateDto createDto = new ContractEnterpriseCreateDto();
        BeanUtils.copyProperties(createVo, createDto);
        createDto.setContractType(ContractEnterpriseTypeEnum.CAR_CONTRACT.getValue());
        String contractUrl = createVo.getContractUrl();
        createDto.setContractUrls(Arrays.asList(
                new ContractFileCreateDto(createVo.getContractName(), createVo.getContractUrl())));
        return createDto;
    }

    public static OrderEnterpriseCarReturnVo toOrderEnterpriseCarReturnVo(EnterpriseCarHandoverDto enterpriseCarHandoverDto,
                                                                          CarDto carDto, IovFenceDto iovFenceDto,
                                                                          EntrepotStorageDto entrepotStorageDto, ContractEnterpriseDto contractEnterpriseDto) {
        if (enterpriseCarHandoverDto == null) {
            return null;
        }
        OrderEnterpriseCarReturnVo vo = new OrderEnterpriseCarReturnVo();
        BeanUtils.copyProperties(enterpriseCarHandoverDto, vo);
        if (iovFenceDto != null) {
            vo.setFenceName(iovFenceDto.getFenceName());
        }
        if (entrepotStorageDto != null) {
            vo.setStockName(entrepotStorageDto.getShortName());
        }
        if (contractEnterpriseDto != null) {
            List<ContractFileDto> contracts = contractEnterpriseDto.getContractUrls();
            if (contracts != null && contracts.size() > 0) {
                vo.setContractName(contracts.get(0).getContractName());
                vo.setContractUrl(contracts.get(0).getContractUrl());
            }
        }
        return vo;
    }

    public static EnterprisePayModifyBizDto toEnterprisePayModifyBizDto(EnterprisePayCreateVo createVo) {
        if (createVo == null) {
            return null;
        }
        EnterprisePayModifyBizDto modifyBizDto = new EnterprisePayModifyBizDto();
        BeanUtils.copyProperties(createVo, modifyBizDto);
        modifyBizDto.setPayTime(DateUtil.parseDateTime(createVo.getPayTime()));
        return modifyBizDto;
    }

    public static PaymentEnterpriseCreateDto toPaymentEnterpriseCreateDto(EnterprisePayCreateVo createVo) {
        if (createVo == null) {
            return null;
        }

        PaymentEnterpriseCreateDto createDto = new PaymentEnterpriseCreateDto();
        BeanUtils.copyProperties(createVo, createDto);
        createDto.setPayTime(DateUtil.parseDateTime(createVo.getPayTime()));
        createDto.setVoucherImgs(createVo.getVoucherImg());
        return createDto;
    }

    public static EnterpriseScheduleVerifyVo toEnterpriseScheduleVerifyVo(EnterpriseScheduleDto dto) {
        if (dto == null) {
            return null;
        }
        EnterpriseScheduleVerifyVo vo = new EnterpriseScheduleVerifyVo();

        BeanUtils.copyProperties(dto, vo);
        return vo;
    }

    public static OrderEnterpriseListVo toEnterpriseListBizVo(OrderEnterpriseBizDto orderEnterpriseBizDto) {
        if (orderEnterpriseBizDto == null) {
            return null;
        }
        OrderEnterpriseListVo vo = new OrderEnterpriseListVo();
        BeanUtils.copyProperties(orderEnterpriseBizDto, vo);
        return vo;

    }

    public static OrderEnterpriseCarBizVo toEnterpriseCarBizVo(OrderEnterpriseCarBizDto orderEnterpriseCarBizDto) {
        if (orderEnterpriseCarBizDto == null) {
            return null;
        }
        OrderEnterpriseCarBizVo vo = new OrderEnterpriseCarBizVo();
        BeanUtils.copyProperties(orderEnterpriseCarBizDto, vo);
        return vo;
    }

    public static OrderEnterpriseLeaseConfirmBizDto toOrderEnterpriseLeaseConfirmBizDto(EnterpriseLeaseConfirmCreateVo createVo) {
        if (createVo == null) {
            return null;
        }
        OrderEnterpriseLeaseConfirmBizDto createBizDto = new OrderEnterpriseLeaseConfirmBizDto();

        createBizDto.setOrderCode(createVo.getOrderCode());
        LocalDate date = DateUtil.parseDate(createVo.getLeaseInception());
        createBizDto.setLeaseInception(date);

        return createBizDto;
    }

    public static EnterpriseAndCarVo toEnterpriseAndCarVo(OrderEnterpriseDto enterpriseDto,
                                                          List<EnterpriseCarDto> enterpriseCarDtos) {
        if (enterpriseDto == null) {
            return null;
        }

        EnterpriseAndCarVo vo = new EnterpriseAndCarVo();
        BeanUtils.copyProperties(enterpriseDto, vo);
        // 剩余保证金
        BigDecimal deposit = BigDecimal.ZERO;
        if (enterpriseCarDtos != null && !enterpriseCarDtos.isEmpty()) {
            List<EnterpriseModelDetailVo> modelDetail = new ArrayList<>();
            EnterpriseModelDetailVo modelDetailVo = new EnterpriseModelDetailVo();
            for (EnterpriseCarDto enterpriseCarDto : enterpriseCarDtos) {
                deposit = deposit.add(enterpriseCarDto.getDeposit());

            }


            vo.setModelDetail(modelDetail);
        }

        vo.setDeposit(deposit);

        return vo;

    }

    public static EnterpriseAndCarVo toEnterpriseAndCarVo(OrderEnterpriseDto enterpriseDto,
                                                          Map<Integer, List<EnterpriseCarDto>> dtoMap,
                                                          Map<Integer, CarDto> carMap,
                                                          Map<Integer, VehicleNameBizDto> vehicleMap,
                                                          Map<Integer, VehicleColorDto> colorMap) {
        if (enterpriseDto == null) {
            return null;
        }
        EnterpriseAndCarVo vo = new EnterpriseAndCarVo();
        BeanUtils.copyProperties(enterpriseDto, vo);
        // 剩余保证金
        vo.setDeposit(BigDecimal.ZERO);
        if (dtoMap == null || dtoMap.isEmpty()) {
            return vo;
        }
        vo.setModelDetail(new ArrayList<>());
        // 遍历车型
        vehicleMap.forEach((modelId, vehicleNameBizDto) -> {
            // 获取该车型下的车辆信息
            List<EnterpriseCarDto> enterpriseCarDtos = dtoMap.get(modelId);
            // 车型明细
            EnterpriseModelDetailVo modelDetailVo = new EnterpriseModelDetailVo(vehicleNameBizDto.getModelName(),
                    enterpriseCarDtos.size(), new ArrayList<>(enterpriseCarDtos.size()));
            // 遍历
            enterpriseCarDtos.forEach(enterpriseCarDto -> {
                // 车辆保证金
                vo.setDeposit(vo.getDeposit().add(enterpriseCarDto.getDeposit()));

                // 车辆明细
                EnterpriseCarDetailVo carDetailVo = new EnterpriseCarDetailVo();
                BeanUtils.copyProperties(enterpriseCarDto, carDetailVo);
                carDetailVo.setRepaymentPeriod(enterpriseDto.getRepaymentPeriod());
                carDetailVo.setRepaymentPeriodStr(enterpriseDto.getRepaymentPeriod() + "月");

                // 获取车辆信息
                if (carMap != null) {
                    CarDto carDto = carMap.get(enterpriseCarDto.getCarId());
                    carDetailVo.setVin(carDto == null ? null : carDto.getVin());
                    carDetailVo.setLicencePlate(carDto == null ? null : carDto.getLicencePlate());
                    carDetailVo.setVehicleType(carDto == null ? null : carDto.getVehicleType());
                    carDetailVo.setVehicleTypeStr(carDto == null ? null : carDto.getVehicleTypeStr());
                }
                // 获取车身颜色信息
                if (colorMap != null) {
                    VehicleColorDto vehicleColorDto = colorMap.get(enterpriseCarDto.getColorId());
                    carDetailVo.setColorName(vehicleColorDto == null ? null : vehicleColorDto.getName());
                }
                modelDetailVo.getCarDetail().add(carDetailVo);
            });
            vo.getModelDetail().add(modelDetailVo);
        });

        return vo;
    }

    public static OrderRepaymentDetailVo toOrderRepaymentDetailVo(EnterpriseScheduleBizDto bizDto) {
        if (bizDto == null) {
            return null;
        }
        OrderRepaymentDetailVo vo = new OrderRepaymentDetailVo();
        BeanUtils.copyProperties(bizDto, vo);
        vo.setId(bizDto.getScheduleId());
        vo.setPeriodsStr(bizDto.getPeriods() + "/" + bizDto.getTotalPeriods());
        vo.setPayable(bizDto.getAllPayable());
        vo.setStatus(bizDto.getState());
        vo.setStatusStr(bizDto.getStateStr());
        vo.setPaySuccessTime(bizDto.getPayTime());
        vo.setIsOverdue(bizDto.getOverdueDays() > 0);
        if (DateUtil.getDaysDiff(bizDto.getPayableDate(), LocalDate.now()) > 0
                || bizDto.getState() == EnterpriseScheduleStateEnum.ALREADY.getValue()) {
            vo.setIsOverdueStr(vo.getIsOverdue() ? "是" : "否");
            vo.setOverdueDaysStr(vo.getOverdueDays() == null ?
                    null : vo.getOverdueDays() <= 0 ?
                    null : vo.getOverdueDays() + "天");
        }

        return vo;
    }

    public static OrderEnterpriseBaseVo toOrderEnterpriseBaseVo(OrderEnterpriseDto dto,
                                                                ContractEnterpriseDto contractEnterpriseDto,
                                                                EnterpriseDto enterpriseDto) {
        if (dto == null) {
            return null;
        }

        OrderEnterpriseBaseVo vo = new OrderEnterpriseBaseVo();
        BeanUtils.copyProperties(dto, vo);
        vo.setTenancyStr(dto.getTenancy() + "月");
        vo.setRepaymentPeriodStr(dto.getRepaymentPeriod() + "月");
        BeanUtils.copyProperties(contractEnterpriseDto, vo);
        vo.setResponsibleAccountName(enterpriseDto == null ? null : enterpriseDto.getResponsibleAccountName());
        vo.setResponsibleAccountPhone(enterpriseDto == null ? null : enterpriseDto.getResponsibleAccountPhone());

        return vo;
    }

    public static LawsuitCreateBizDto toLawsuitCreateBizDto(OrderLawsuitCreateVo createVo) {
        if (createVo == null) {
            return null;
        }
        LawsuitCreateBizDto createBizDto = new LawsuitCreateBizDto();
        BeanUtils.copyProperties(createVo, createBizDto);

        return createBizDto;
    }

    public static OrderLawsuitVo toOrderLawsuitVo(LawsuitListDto dto) {
        if (dto == null) {
            return null;
        }
        OrderLawsuitVo vo = new OrderLawsuitVo();
        BeanUtils.copyProperties(dto, vo);
        vo.setOverdueDaysStr(vo.getOverdueDays() + "日");
        vo.setOverdueNumStr(vo.getOverdueNum() + "次");

        return vo;
    }

    public static OrderNegotiateRenegeVo toOrderNegotiateRenegeVo(OrderNegotiateRenegeDto dto) {
        if (dto == null) {
            return null;
        }
        OrderNegotiateRenegeVo vo = new OrderNegotiateRenegeVo();
        BeanUtils.copyProperties(dto, vo);
        vo.setOverdueDaysStr(vo.getOverdueDays() + "日");
        vo.setOverdueNumStr(vo.getOverdueNum() + "次");

        return vo;
    }

    public static RecycleCarsCreateBizDto toRecycleCarsCreateBizDto(OrderRecycleCarsCreateVo createVo) {
        if (createVo == null) {
            return null;
        }
        RecycleCarsCreateBizDto createBizDto = new RecycleCarsCreateBizDto();
        BeanUtils.copyProperties(createVo, createBizDto);
        createBizDto.setRecycleState(RecycleStateEnum.getEnum(createVo.getRecycleState()));
        createBizDto.setRecycleTime(LocalDateTime.now());

        return createBizDto;


    }
}
